package com.fanyouzhao.ehome.util;

import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import com.aliyun.teaopenapi.models.Config;

/**
 * 阿里云发短信工具类
 * @Author: fanyouzhao
 * @Date: 10:11 2021/5/12
 */
public class AliMsm {

    public static String sendMsg(String phone, String code) throws Exception {
        java.util.List<String> args = java.util.Arrays.asList();
        com.aliyun.dysmsapi20170525.Client client = AliMsm.createClient("LTAI4G8ScutKDrZVBDNj1hBz", "RFe9gFe00g98zoIHDg4tAPXQMmVNoP");
        SendSmsRequest sendSmsRequest = new SendSmsRequest()
                .setPhoneNumbers(phone)
                .setSignName("友钊科技")
                .setTemplateCode("SMS_187944251")
                .setTemplateParam("{\"code\":"+code+"}");
        SendSmsResponse sendSmsResponse = client.sendSms(sendSmsRequest);
        return sendSmsResponse.getBody().getCode();
    }
    /**
     * 使用AK&SK初始化账号Client
     * @param accessKeyId
     * @param accessKeySecret
     * @return Client
     * @throws Exception
     */
    public static com.aliyun.dysmsapi20170525.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
        Config config = new Config()
                .setAccessKeyId(accessKeyId)
                .setAccessKeySecret(accessKeySecret);
        // 访问的域名
        config.endpoint = "dysmsapi.aliyuncs.com";
        return new com.aliyun.dysmsapi20170525.Client(config);
    }
}
